﻿#region License

// Created by John Batte on 04/03/2012 at 10:08 PM.
// Last code cleanup: 04/04/2012 at 6:07 AM.
// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace BatteCode.Google.Wiki
{
	/// <summary>
	/// Provides a wiki scanner.
	/// </summary>
	public class WikiScanner : IWikiScanner
	{
		#region IWikiScanner Members

		/// <summary>
		/// Gets the wiki-compatible members.
		/// </summary>
		/// <param name="targetType">Type of the target.</param>
		/// <returns></returns>
		public IEnumerable<MemberInfo> GetWikiMembers(Type targetType)
		{
			return targetType.GetMembers()
				.Where(x => !IsPropertyAccessor(x) && x.DeclaringType == targetType);
		}

		#endregion

		private static bool IsPropertyAccessor(MemberInfo member)
		{
			return member.MemberType == MemberTypes.Method && (member.Name.StartsWith("get_") || member.Name.StartsWith("set_"));
		}
	}
}